package model.posterminal;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value="posterminalModelConverter")
public class PosterminalModelConverter implements Converter{


	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
		try {
			return PosterminalModelDAO.find(Long.parseLong(value));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println(e.toString());
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
		try {
			return ((PosterminalModel) value).getId().toString();
		} catch (Exception e) {
			//TODO logging THIS!
			System.out.println("String data: " + value.toString());
			e.printStackTrace();
		}
		return null;
	}
	
}
